#!/usr/bin/env python

# Copyright (C) 2011 Victor Semionov <vsemionov@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#  * Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#  * Neither the name of the copyright holder nor the names of the contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


import wx

from flea_wdr import *


app_name = "FLEA"
app_version = "0.1-dev"
copyright = "Copyright (C) 2011 Victor Semionov <vsemionov@gmail.com>"
rights = "All rights reserved."


# WDR: classes

class FuelingDialog(wx.Dialog):
    def __init__(self, parent, id, title,
        pos = wx.DefaultPosition, size = wx.DefaultSize,
        style = wx.DEFAULT_DIALOG_STYLE ):
        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
        
        # WDR: dialog function FuelingDialogFunc for FuelingDialog
        FuelingDialogFunc( self, True )
        
        # WDR: handler declarations for FuelingDialog
        wx.EVT_BUTTON(self, wx.ID_OK, self.OnOk)

    # WDR: methods for FuelingDialog

    def Validate(self, win):
        return True

    def TransferDataToWindow(self):
        return True

    def TransferDataFromWindow(self):
        return True

    # WDR: handler implementations for FuelingDialog

    def OnOk(self, event):
        event.Skip(True)


class EntriesDialog(wx.Dialog):
    def __init__(self, parent, id, title,
        pos = wx.DefaultPosition, size = wx.DefaultSize,
        style = wx.DEFAULT_DIALOG_STYLE ):
        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
        
        # WDR: dialog function EntriesDialogFunc for EntriesDialog
        EntriesDialogFunc( self, True )
        
        # WDR: handler declarations for EntriesDialog
        wx.EVT_BUTTON(self, ID_ADD, self.OnAdd)
        wx.EVT_BUTTON(self, ID_EDIT, self.OnEdit)
        wx.EVT_BUTTON(self, ID_DELETE, self.OnDelete)

    # WDR: methods for EntriesDialog

    # WDR: handler implementations for EntriesDialog

    def OnAdd(self, event):
        pass

    def OnEdit(self, event):
        pass

    def OnDelete(self, event):
        pass


class FLEAFrame(wx.Frame):
    def __init__(self, parent, id, title,
        pos = wx.DefaultPosition, size = wx.DefaultSize,
        style = wx.DEFAULT_FRAME_STYLE ):
        wx.Frame.__init__(self, parent, id, title, pos, size, style)
        
        self.CreateMyMenuBar()
        
        self.CreateMyToolBar()
        
        self.CreateStatusBar(1)
        self.SetStatusText("Welcome!")
        
        # insert main window here
        toolbar = self.GetToolBar()
        toolbar.FindControl(ID_FILTER_VEHICLES).Selection = 0
        toolbar.FindControl(ID_FILTER_FUELS).Selection = 0
        fuelings = wx.ListCtrl(self, style=wx.LC_REPORT)
        fuelings.InsertColumn(0, "Vehicle")
        fuelings.InsertColumn(1, "Fuel")
        fuelings.InsertColumn(2, "Quantity")
        fuelings.InsertColumn(3, "Odometer")
        fuelings.InsertColumn(4, "Date")
        self.fuelings = fuelings
        
        # WDR: handler declarations for FLEAFrame
        wx.EVT_TOOL(self, ID_ADD_FUELING, self.OnAdd)
        wx.EVT_CHOICE(self, ID_FILTER_VEHICLES, self.OnFilterVehicles)
        wx.EVT_CHOICE(self, ID_FILTER_FUELS, self.OnFilterFuels)
        wx.EVT_MENU(self, ID_VEHICLES, self.OnVehicles)
        wx.EVT_MENU(self, ID_VEHICLES, self.OnFuels)
        wx.EVT_MENU(self, ID_ADD_FUELING, self.OnAdd)
        wx.EVT_MENU(self, ID_EDIT_FUELING, self.OnEdit)
        wx.EVT_MENU(self, ID_DELETE_FUELING, self.OnDelete)
        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
        wx.EVT_MENU(self, wx.ID_EXIT, self.OnQuit)
        wx.EVT_CLOSE(self, self.OnCloseWindow)
        wx.EVT_SIZE(self, self.OnSize)
        wx.EVT_UPDATE_UI(self, -1, self.OnUpdateUI)
        
    # WDR: methods for FLEAFrame
    
    def CreateMyMenuBar(self):
        self.SetMenuBar( MyMenuBarFunc() )
    
    def CreateMyToolBar(self):
        tb = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER)
        MyToolBarFunc( tb )
    
    # WDR: handler implementations for FLEAFrame
    
    def OnFilterVehicles(self, event):
        pass

    def OnFilterFuels(self, event):
        pass

    def OnVehicles(self, event):
        dlg = EntriesDialog(self, -1, "Vehicles")
        dlg.CenterOnParent()
        dlg.ShowModal()
        dlg.Destroy()

    def OnFuels(self, event):
        dlg = EntriesDialog(self, -1, "Fuels")
        dlg.CenterOnParent()
        dlg.ShowModal()
        dlg.Destroy()

    def OnAdd(self, event):
        dlg = FuelingDialog(self, -1, "Add Fueling")
        dlg.CenterOnParent()
        dlg.ShowModal()
        dlg.Destroy()

    def OnEdit(self, event):
        pass

    def OnDelete(self, event):
        pass

    def OnAbout(self, event):
        dialog = wx.MessageDialog(self,
            "Welcome to {} {}\n\n{}\n{}".format(app_name, app_version, copyright, rights),
            "About {}".format(app_name),
            wx.OK|wx.ICON_INFORMATION)
        dialog.CenterOnParent()
        dialog.ShowModal()
        dialog.Destroy()
    
    def OnQuit(self, event):
        self.Close(True)
    
    def OnCloseWindow(self, event):
        self.Destroy()
    
    def OnSize(self, event):
        event.Skip(True)
    
    def OnUpdateUI(self, event):
        event.Skip(True)
    

#----------------------------------------------------------------------------

class FLEA(wx.App):
    
    def OnInit(self):
        wx.InitAllImageHandlers()
        frame = FLEAFrame(None, -1, app_name, size=[800,600])
        frame.Center()
        frame.Show(True)
        
        return True

#----------------------------------------------------------------------------

app = FLEA(True)
app.MainLoop()
